
#include "stdafx.h"
#include "ConstDef.h"
#include "ReloadCode.h"
#include "ReloadPacket.h"
#include "ReloadConfigure.h"
#include "ReloadApp.h"
#include "ReloadPacket.h"
#include "ReloadOverlay.h"

namespace reload
{
	ReloadApp::ReloadApp( asyframe::ConfigureBase* _pConfigure /*= new asyframe::ConfigureBase()*/ )
	:asyframe::AppBase(_pConfigure),pReloadConfigure_(),overlays_()
	{

	}

	ReloadApp::~ReloadApp()
	{
		pReloadConfigure_.reset();
		overlays_.clear();
	}

	retT ReloadApp::init()
	{
		R(asyframe::AppBase::init());
		pReloadConfigure_.reset(new ReloadConfigure());
		R(pReloadConfigure_->init(((ReloadAppConfigure*)pConfigure_)->reloadConfigureFileName_));
		for(boost::unordered_map<asyframe::uint32, OverlayConfiguration>::iterator it = pReloadConfigure_->overlay_.begin(); it != pReloadConfigure_->overlay_.end(); ++it)
		{
			boost::shared_ptr<ReloadOverlay> pReloadOverlay(new ReloadOverlay(it->first));
			R(pReloadOverlay->attachHandlerOwner(shared_from_this()));
			overlays_[it->first] = pReloadOverlay;
			R(attachInstance(pReloadOverlay));
		}
		RETSUCCESS;
	}

	boost::shared_ptr<ReloadConfigure> ReloadApp::getReloadConfigure()
	{
		return pReloadConfigure_;
	}

	boost::shared_ptr<ReloadOverlay> ReloadApp::getOverlay( asyframe::uint32 _overlayNameHash )
	{
		return overlays_[_overlayNameHash].lock();
	}

	boost::shared_ptr<ReloadOverlay> ReloadApp::getOverlay( std::string _overlayInstanceName )
	{
		return getOverlay(SHA1HashValue(_overlayInstanceName.c_str()));
	}
} /*namespace reload*/
